﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DinhMuc.UI.Form_bang;
using DinhMuc.UI.UC;
using DinhMuc.UI.frm_Report;

namespace DinhMuc.UI.Frm_Form
{
    public partial class frm_MAIN : Form
    {
        public frm_MAIN()
        {
            InitializeComponent();
        }
        public static bool isLogIn = false;
        private void buttonCommand5_Click(object sender, Janus.Windows.Ribbon.CommandEventArgs e)
        {
            Janus.Windows.Ribbon.ButtonCommand button = (Janus.Windows.Ribbon.ButtonCommand)sender;
            DevExpress.XtraTab.XtraTabPage page = new DevExpress.XtraTab.XtraTabPage();
            page.Name = button.Name;
            page.Text = button.Text;
            int kq = 0;
            for (int i = 0; i < xtraTabControl1.TabPages.Count; i++)
            {
                DevExpress.XtraTab.XtraTabPage pageCon = xtraTabControl1.TabPages[i];
                if (pageCon.Text.ToUpper() == button.Text.ToUpper())
                {
                    kq = 1;
                    xtraTabControl1.SelectedTabPageIndex = i;
                    break;
                }
                
            }
            if (kq == 0)
            {
                xtraTabControl1.TabPages.Add(page);
                xtraTabControl1.SelectedTabPageIndex = xtraTabControl1.TabPages.Count - 1;
            }
           
        }

        private void uiTab1_SelectedTabChanged(object sender, Janus.Windows.UI.Tab.TabEventArgs e)
        {
           
        }

        private void frm_MAIN_Load(object sender, EventArgs e)
        {
            frmHome();
            if (!isLogIn)
            {
                frmLogin frm = new frmLogin();
                frm.ShowDialog();
            }
                            
        }
        private void frmHome()
        {
            UserControl control = new ucTrangChu();
            control.Dock = System.Windows.Forms.DockStyle.Fill;
            tabHome.Controls.Add(control);
        }

        private void xtraTabControl1_CloseButtonClick(object sender, EventArgs e)
        {
            DevExpress.XtraTab.XtraTabControl tabControl = (DevExpress.XtraTab.XtraTabControl)sender;
            int i = xtraTabControl1.SelectedTabPageIndex;
            xtraTabControl1.TabPages.RemoveAt(i);
            xtraTabControl1.SelectedTabPageIndex = i - 1;
        }

        private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            try
            {
                DevExpress.XtraTab.XtraTabControl tab = (DevExpress.XtraTab.XtraTabControl)sender;
                
                if (tab.SelectedTabPage.Text.ToLower() == "danh sách khách hàng")
                {
                    UserControl control = new frm_khachHang();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text.ToLower() == "danh sách đơn hàng")
                {
                    UserControl control = new frm_QLDonHang();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text.ToLower() == "danh sách sản phẩm")
                {
                    UserControl control = new frm_sanPham();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text.ToLower() == "danh sách nguyên liệu")
                {
                    UserControl control = new frm_nguyenVatLieu();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text == "Định Mức Thành Phẩm- Nguyên Vật Liệu- Phế Liệu")
                {
                    UserControl control = new frm_DinhMuc();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text.ToLower() == "thống kê sản xuất thành phẩm")
                {
                    UserControl control = new TKSX_TP();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text.ToLower() == "thống kê sản xuất nvl")
                {
                    UserControl control = new TKSX_NVL();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Text.ToLower() == "thống kê sản xuất phế liệu")
                {
                    UserControl control = new TKSX_PL();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand17")
                {
                    UserControl control = new ucThemMoiTKSX();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand19")
                {
                    UserControl control = new rp_TKSX_ALL();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand20")
                {
                    UserControl control = new rp_TKSX_Thoi();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand21")
                {
                    UserControl control = new rp_TKSX_TrangL1();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand22")
                {
                    UserControl control = new rp_TKSX_TrangL2();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand23")
                {
                    UserControl control = new rp_TKSX_in();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand24")
                {
                    UserControl control = new rp_TKSX_chiaCuon();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }
                if (tab.SelectedTabPage.Name == "buttonCommand25")
                {
                    UserControl control = new rp_TKSX_catDan();
                    control.Dock = System.Windows.Forms.DockStyle.Fill;
                    tab.SelectedTabPage.Controls.Add(control);
                }


            }
            catch (Exception)
            {
            }
        }
    }
}
